<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../common.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>监控抄送管理列表</title>
</head>
<body class="easyui-layout">
<!-- 表单 -->
<form id="ff" action="${ctx}/monitorCc/upd" method="post" data-options="novalidate:true">
	<input type="hidden" id="id" name="id">
	<input type="hidden" id="itemId" name="itemId" >
	<div style="margin-bottom:15px">
		<input class="easyui-textbox" id="ccName" name="ccName" style="width:95%" data-options="label:'抄送人:',required:true">
	</div>
	<div style="margin-bottom:15px">
		<input class="easyui-textbox" id="email" name="email" style="width:95%" data-options="label:'邮箱地址:',required:true">
	</div>
</form>
<div style="text-align:center;padding:5px 0">
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">Submit</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">Clear</a>
</div>
<!-- 列表 -->
<input type="hidden" id="item_id" name="item_id" value="${itemId}">
<table id="list"></table>
<!-- 脚本 -->
<script>
$(function() { 
	// 初始化抄送列表
	$('#list').datagrid({
		url: '${ctx}/monitorCc/monitorCcList',
		queryParams:{"itemId":$("#item_id").val()},
		height: size.height-120,
		idField: 'id',
		nowrap: false, //内容换行
		striped: true, //条纹
        fit: true,
		singleSelect: true, //是否单选
        frozenColumns: [[
        	{field:'ck',checkbox:true}
        ]],
		columns: [[
			{field:"id",title:"编号",align:"center",width:fixWidth(0.1)},  
			{field:"ccName",title:'抄送人姓名',width:fixWidth(0.1)},
			{field:"email",title:'抄送邮箱地址',align:"center",width:fixWidth(0.4)},
			{field:"_opt",title:'操作',align:"center",width:fixWidth(0.1),
				formatter : function(value, rowData) {
					return '<a style="color:blue" href="#" onclick="delCc('+rowData.id+')" >删除</a> &nbsp;&nbsp;'; ;
				}	
			}
		]],
		onDblClickRow: function (rowIndex, rowData) {  
			initForm(rowData);
		},
		rownumbers : true, //记录号
		pagination : true,
        toolbar: "#tb"
	}); 
	//初始化分页
	initListPage("list");
	// 消息提醒
	var message = $("#message").val();
	if(message){
		$.messager.alert('提示', message);
		parent.reloadList();
	}
});

//加载表单信息
function initForm(data){
	if(!data){
		return;
	}
	$('#ff').form('load',{
		id:data.id,
		ccName:data.ccName,
		email:data.email
	});
}
//提交
function submitForm(){
	//数据检查
	if(!$('#ff').form('enableValidation').form('validate')){
		return;
	}
	//提交
	$.ajax({
		url:'${ctx}/monitorCc/upd',
		type: "POST",
		data: {
			"id": $("#id").val(),
			"itemId": $("#item_id").val(),
			"ccName": $("#ccName").val(),
			"email": $("#email").val()
		},
		dataType:'json',
		success: function(opt){
			reloadList();
			alert(opt.message);
		}
	});
}
//重置
function clearForm(){
	$('#ff').form('clear');
}
// 删除
function delCc(id){
	$.ajax({
		url:'${ctx}/monitorCc/deleteMonitorCc?id='+id,
		type: "POST",
		dataType:'json',
		success: function(opt){
			if(opt.success){
				reloadList();
			}
			alert(opt.message);
		}
	});
}
</script>
</body>
</html>
